var fileAdmin = {

	// 重载Label控件
	my_override_label : Ext.override(Ext.form.Label, {
		setText : function(t) {
			this.text = t;
			if (this.rendered) {
				this.el.update(t);
			}
		},
		getText : function() {
			return this.text;
		},
		width : 500,
	}),

	show_file_admin : function() {
		var total_text = '平台存储的文件碎片数为：';
		var qiniu_text = '七牛云存储的文件碎片数为：';
		var qiniu2_text = '七牛云2存储的文件碎片数为：';
		var jinshan_text = '金山云存储的文件碎片数为：';
		var total_label = new this.my_override_label({
			text : total_text,
		})
		var qiniu_label = new this.my_override_label({
			text : qiniu_text,
		})
		var qiniu2_label = new this.my_override_label({
			text : qiniu2_text,
		})
		var jinshan_label = new this.my_override_label({
			text : jinshan_text,
		})
		

		// 饼图
		var store = Ext.create('Ext.data.Store', {
			storeId : "chart_store",
			fields : [ 'name', 'data' ],
			proxy : {
				type : "ajax",
				url : 'filestatistics',
				extraParams : {
					'adminOpt' : 'piecharts',
				},
				reader : {
					type : 'json',
				},
			},
			autoLoad : false,
		});
		store.load({
			callback : function() {
				var total = 0;
				store.each(function(rec) {
					total += rec.get('data');
					var name = rec.get('name');
					if (name == "金山云")
						jinshan_label.setText(jinshan_text + rec.get('data'));
					else if (name == "七牛云")
						qiniu_label.setText(qiniu_text + rec.get('data'));
					else if (name == "七牛云2")
						qiniu2_label.setText(qiniu2_text + rec.get('data'));
				});
				total_label.setText(total_text + total);
			}
		});

		this.chart = Ext.create('Ext.chart.Chart', {
			width : 500,
			height : 350,
			xtype : 'chart',
			animate : true,
			store : store,
			theme : 'Base:gradients',
			series : [ {
				type : 'pie',
				angleField : 'data',
				showInLegend : false,
				tips : {
					trackMouse : true,
					width : 140,
					height : 28,
					renderer : function(storeItem, item) {
						var total = 0;
						store.each(function(rec) {
							total += rec.raw.data;
						});
						this.setTitle(storeItem.get('name')
								+ ': '
								+ Math.round(storeItem.get('data') / total
										* 100) + '%');
					}
				},
				highlight : {
					segment : {
						margin : 20
					}
				},
				label : {
					field : 'name',
					display : 'rotate',
					contrast : true,
					font : '18px Arial'
				},
				colorSet : [ "#115fa6", "#94ae0a", "#a61120", "#ff8809" ],
			} ],
		});

		var form = new Ext.form.FormPanel({
			frame : true,
			layout : {
				type : 'vbox',
				align : 'stretch',
				padding : 5,
			},
			title : "文件统计",
			style : "margin:10px",
			buttonAlign : 'left',
			bodyStyle : 'padding:6px 0px 0px 15px',
			items : [ total_label, jinshan_label, qiniu_label, qiniu2_label ],
			labelAlign : 'right',
			labelWidth : 45,
		});

		this.chart_panel = new Ext.panel.Panel({
			title : '文件统计图',
			style : 'margin:10px',
			bodyStyle : 'padding:6px 0px 0px 15px',
			items : [ this.chart ],
			tools : [ {
				type : 'refresh'
			}, {
				type : 'help'
			} ],
		});

		// 弹出的窗口
		var win = new Ext.Window({
			title : '统计',
			width : 600,
			height : 600,
			resizable : true,
			modal : true,
			closable : true,
			maximizable : true,
			minimizable : true,
			items : [ form, this.chart_panel ],
		});
		win.show();
	},
}
